package com.yy.cloud.filters;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

/**
 * 自定义全局的日志过滤器
 *
 * @date 2024/5/11
 */
@Component
public class GlobalLogFilter implements GlobalFilter {
    Logger log = LoggerFactory.getLogger(GlobalLogFilter.class);

    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
        // 记录请求路径
        log.info("请求路径：{}", exchange.getRequest().getPath().value());
        return chain.filter(exchange); // 放行
    }
}
